
	use "$dir/rawdata/LSMS Malawi/2019/HH_MOD_B.dta", clear // household roster
	
	/*
		5 MODULE B: HOUSEHOLD ROSTER 
		8 MODULE C: EDUCATION
		11 MODULE D: HEALTH
		16 MODULE E: TIME USE & LABOUR 
		32 MODULE F: HOUSING
		35 MODULE F_1: LAND ROSTER
		47 MODULE H: FOOD SECURITY
		48 MODULE I: NON-FOOD EXPENDITURES – OVER PAST ONE WEEK & ONE MONTH
		49 MODULE J: NON-FOOD EXPENDITURES
		50 MODULE K: NON-FOOD EXPENDITURES OVER PAST 12 MONTHS
		51 MODULE L: DURABLE GOODS
		53 MODULE M: FARM IMPLEMENTS, MACHINERY, AND STRUCTURES
		55 MODULE N: HOUSEHOLD ENTERPRISES
		63 MODULE O: CHILDREN LIVING ELSEWHERE
		65 MODULE P: OTHER INCOME
		67 MODULE Q: GIFTS GIVEN OUT
		68 MODULE R: SOCIAL SAFETY NETS
		70 MODULE S: CREDIT
		72 MODULE T: SUBJECTIVE ASSESSMENT OF WELL-BEING 
		74 MODULE U: SHOCKS & COPING STRATEGIES
		75 MODULE V: CHILD ANTHROPOMETRY
		76 MODULE W: DEATHS
		77 MODULE X: FILTER QUESTIONS FOR AGRICULTURE &
		FISHERY QUESTIONNAIRES
	*/
	
	merge m:1 case_id using "$dir/rawdata/LSMS Malawi/2019/ihs5_consumption_aggregate.dta" // consumption aggregate
	merge 1:1 case_id PID using "$dir/rawdata/LSMS Malawi/2019/HH_MOD_D.dta", keep(master matched) nogen // health
	merge 1:1 case_id PID using "$dir/rawdata/LSMS Malawi/2019/HH_MOD_E.dta", keep(master matched) nogen // time use and labor
	merge m:1 case_id using "$dir/rawdata/LSMS Malawi/2019/HH_MOD_T.dta", keep(master matched) nogen // subjective well-being
	
	ren case_id hhid 
	ren PID indiv
	
	 ** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
			gen w5_inhh=1 // FIXME: No specific question asking this
		
		** Age
			gen w5_age=hh_b05a
			
		** Household size
			gen temp=1 if w5_inhh==1
			bys hhid: egen w5_hh_size=total(temp)
			drop temp

		** Number of children 12 or younger
			gen temp=1 if w5_age<=12 & w5_inhh==1
			bys hhid: egen w5_hh_under12=total(temp)
			drop temp

		** Number of youth 18 or younger
			gen temp=1 if w5_age<=18 & w5_inhh==1
			bys hhid: egen w5_hh_under18=total(temp)
			drop temp

		** Number of adults 60 or older
			gen temp=1 if w5_age>=60 & !missing(w5_age) & w5_age!=999 & w5_inhh==1
			bys hhid: egen w5_hh_over60=total(temp)
			drop temp

		** Adults 12 to 60
			gen temp=1 if w5_age>12 & w5_age<60 & !missing(w5_age) & w5_age!=999 & w5_inhh==1
			bys hhid: egen w5_hh_12to60=total(temp)
			drop temp

		** Marital status
			gen w5_married=(hh_b24==1 | hh_b24==2) if !missing(hh_b24)
			gen w5_married_monog=(hh_b24==1) if !missing(hh_b24)
			gen w5_married_polyg=(hh_b24==2) if !missing(hh_b24)

		** Female
			gen w5_female=(hh_b03==2) if !missing(hh_b03)

		** Age of spouse
			sum indiv
			forvalues x=1/`r(max)' {
				gen age_person`x'_temp=w5_age if indiv==`x' & !missing(w5_age)
				bys hhid: egen age_person`x'=max(age_person`x'_temp)
				drop age_person`x'_temp
			}

		** Average age of others in the household
			sum indiv 
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if indiv==`x'
			}
			egen w5_hh_avgage=rowmean(age_person*)
			
		** Spouse age
			sum indiv
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if hh_b26a!=`x'
			}
			egen w5_spouse_age=rowmean(age_person*)

		** Age gap
			gen w5_spouse_agegap=w5_age-w5_spouse_age

		** Birth year
			gen w5_birthyear=hh_b06b
			recode w5_birthyear 9999=. 9998=.
			replace w5_birthyear=2019-w5_age if missing(w5_birthyear)
			
	***********
	***********
	
	** Geographic information
	
		gen w5_urban=(urban==1) if !missing(urban)
		
	** Consumption
	
		*gen w5_conspc=expaggpc
		gen w5_conspc=expagg/hhsize
		
				
	***********
	***********

	** LABOR

		** Worked for a non-HH member
			gen w5_work_outsideHH1=hh_e10>0 if !missing(hh_e10) // casual part-time
			gen w5_work_outsideHH2=hh_e11>0 if !missing(hh_e11) // wage or salary labor
		
			egen w5_work_outsideHH=rowmax(w5_work_outsideHH1 w5_work_outsideHH2)
			
			gen w5_work_outsideHH1_hrs=hh_e10 if !missing(hh_e10) // casual part-time
			gen w5_work_outsideHH2_hrs=hh_e11 if !missing(hh_e11) // wage or salary labor
			
			egen w5_work_outsideHH_hrs=rowtotal(w5_work_outsideHH1_hrs w5_work_outsideHH2_hrs), mi 
			replace w5_work_outsideHH_hrs=0 if w5_work_outsideHH==0
			
		** Worked in agriculture for a HH member
			gen w5_work_agHH1=hh_e07a>0 if !missing(hh_e07a) // farming
			gen w5_work_agHH2=hh_e07b>0 if !missing(hh_e07b) // livestock
			gen w5_work_agHH3=hh_e07c>0 if !missing(hh_e07c) // fishing
			
			egen w5_work_agHH=rowmax(w5_work_agHH1 w5_work_agHH2 w5_work_agHH3)
			
			gen w5_work_agHH1_hrs=hh_e07a if !missing(hh_e07a) // farming
			gen w5_work_agHH2_hrs=hh_e07b if !missing(hh_e07b) // livestock
			gen w5_work_agHH3_hrs=hh_e07c if !missing(hh_e07c) // fishing		
			
			egen w5_work_agHH_hrs=rowtotal(w5_work_agHH1_hrs w5_work_agHH2_hrs w5_work_agHH3_hrs), mi
			replace w5_work_agHH_hrs=0 if w5_work_agHH==0
			
		** Worked in HH business
			gen w5_work_bizHH1=hh_e08>0 if !missing(hh_e08) // run biz
			gen w5_work_bizHH2=hh_e09>0 if !missing(hh_e09) // help in biz
			
			egen w5_work_bizHH=rowmax(w5_work_bizHH1 w5_work_bizHH2)
			
			gen w5_work_bizHH1_hrs=hh_e08 if !missing(hh_e08) // run biz
			gen w5_work_bizHH2_hrs=hh_e09 if !missing(hh_e09) // help in biz
					
			egen w5_work_bizHH_hrs=rowtotal(w5_work_bizHH1_hrs w5_work_bizHH1_hrs), mi
			replace w5_work_bizHH_hrs=0 if w5_work_bizHH==0
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w5_worked_last7days=rowmax(w5_work_outsideHH w5_work_agHH w5_work_bizHH)
			
		** Hours worked in last 7 days
			egen w5_work_hrs=rowtotal(w5_work_outsideHH_hrs w5_work_agHH_hrs w5_work_bizHH_hrs)
			replace w5_work_hrs=. if missing(w5_work_outsideHH_hrs) & missing(w5_work_agHH_hrs) & missing(w5_work_bizHH_hrs)
				
		** Works in agriculture
			gen w5_work_agri=(w5_work_agHH==1) if !missing(w5_work_agHH)
		
	***********
	***********

	** HEALTH
		
		** Any illness or injury during the last 2 weeks
			gen w5_ill_inj=(hh_d04==1) if !missing(hh_d04)

		** Had to stop usual activity in the past 4 weeks
			gen w5_ill_inj_stopactivity=(hh_d08>0) if !missing(hh_d08)
			replace w5_ill_inj_stopactivity=0 if w5_ill_inj==0
			
	***********
	***********
	
	** SUBJECTIVE WELL-BEING
	
		** Access to health care
			gen w5_healthcare_inadequate=hh_t04==1 if !missing(hh_t04)
			
		** Food consumption
			gen w5_foodcons_inadequate=hh_t01==1 if !missing(hh_t01)
	
	***********
	***********
		
	** DISABILITIES

	** Difficulty seeing
		tab1 hh_d24, nol
		tab1 hh_d24
		gen w5_diff_seei=1 if inlist(hh_d24, 2, 3, 4) 
		replace w5_diff_seei=0 if inlist(hh_d24, 1)
		replace w5_diff_seei=. if inlist(hh_d24, .)
		tab1 w5_diff_seei

	** Difficulty hearing
		tab1 hh_d25, nol
		tab1 hh_d25
		gen w5_diff_hear=1 if inlist(hh_d25, 2, 3, 4) 
		replace w5_diff_hear=0 if inlist(hh_d25, 1)
		replace w5_diff_hear=. if inlist(hh_d25, .)
		tab1 w5_diff_hear

	** Difficulty walking or climbing stairs	
		tab1 hh_d26, nol
		tab1 hh_d26
		gen w5_diff_walk_clim=1 if inlist(hh_d26, 2, 3, 4) 
		replace w5_diff_walk_clim=0 if inlist(hh_d26, 1)
		replace w5_diff_walk_clim=. if inlist(hh_d26, .)
		tab1 w5_diff_walk_clim

	** Difficulty remembering or concentrating
		tab1 hh_d27, nol
		tab1 hh_d27
		gen w5_diff_reme=1 if inlist(hh_d27, 2, 3, 4) 
		replace w5_diff_reme=0 if inlist(hh_d27,1)
		replace w5_diff_reme=. if inlist(hh_d27, .)
		tab1 w5_diff_reme

	** Difficulty with self-care
		tab1 hh_d28, nol
		tab1 hh_d28
		gen w5_diff_self_care=1 if inlist(hh_d28, 2, 3, 4)
		replace w5_diff_self_care=0 if inlist(hh_d28, 1)
		replace w5_diff_self_care=. if inlist(hh_d28, .)
		tab1 w5_diff_self_care

	** Difficulty communicating
		tab1 hh_d29, nol
		tab1 hh_d29
		gen w5_diff_comm=1 if inlist(hh_d29, 2, 3, 4) 
		replace w5_diff_comm=0 if inlist(hh_d29, 1)
		replace w5_diff_comm=. if inlist(hh_d29, .)
			
	***********
	***********
	
	** SAVE
	
		keep hhid indiv w5*
		order hhid indiv w5*
		save "$dir/data/MLW_w5_individual.dta", replace
